// @charset "utf-8";
/**
 * commonMethod
 */
var commonMethod = {
 	init : function () {
 		var self = this;
 		try {
			self.thsQuote = new ThsQuote();
			self.thsUtil = new ThsUtil();
		} catch (exp) {

		}
		self.changeSkin();
		self.xAxis = self.getxAxis();
		self.emptyData = self.getEmptyData();
 	},
 	xAxis : [],
 	emptyData : [],
 	thsUtil : '',
 	thsQuote : '',
 	thsSkin : 'black',
 	openUrlWeb : function (url, type) {
 		this.thsUtil.openURL(url, type);
 	},
 	getEmptyData : function () {
 		var emptyArr = [];
		for (var i = 0; i < 242; i++) {
			emptyArr.push(null);
		}
		return emptyArr;
 	},
 	completeData : function (arr) {
 		var len = arr.length;
 		if (len < 242) {
 			for (var i = 0; i < 242 - len; i++) {
 				arr.push(null);
 			}
 		}
 		return arr;
 	},
 	changeSkin : function () {
 		var secai = this.thsUtil.getSkinName();
			if (secai == '白色风格') {
				this.thsSkin = 'white';
				$('#links').attr('href', 'css/style-white.css');
			} else {
				this.thsSkin = 'black';
			}
 	},
 	getxAxis : function () {
 		var amTime = [];
		var pmTime = [];
		var m = 9;
		var n = 30;
		var i;
		for (i = 0; i <= 120; i++) {
			if (n > 59) {
				n = 0;
				m += 1;
			}
			amTime.push((m > 9 ? m : "0" + m) + ":" + (n > 9 ? n : "0" + n));
			n += 1;
		}
		m = 13;
		n = 0;
		for (i = 0; i <= 120; i++) {
			if (n > 59) {
				n = 0;
				m += 1;
			}
			pmTime.push((m > 9 ? m : "0" + m) + ":" + (n > 9 ? n : "0" + n));
			n += 1;
		}
		return $.merge(amTime, pmTime);
 	},
 	serverTime : async function () {
 		var timeStamp = await this.thsQuote.getServerTime();
		var time = new Date(timeStamp * 1000);
		var YY = time.getFullYear();
		var MM = (time.getMonth() + 1 < 10 ? '0' +
			(time.getMonth() + 1) : time.getMonth() + 1).toString();
		var DD = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
		var date = YY + '' + MM + '' + DD;
		return date;
 	},
 	_serverTime : async function () {
 		var timeStamp = await this.thsQuote.getServerTime();
		var time = new Date(timeStamp * 1000);
		var YY = time.getFullYear();
		var MM = (time.getMonth() + 1 < 10 ? '0' +
			(time.getMonth() + 1) : time.getMonth() + 1).toString();
		var DD = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
		var date = YY + '-' + MM + '-' + DD;
		return date;
 	},
 	timeStamp : function (timestamp) {
 		var time = new Date(timestamp);
		var YY = time.getFullYear();
		var MM = (time.getMonth() + 1 < 10 ? '0' +
			(time.getMonth() + 1) : time.getMonth() + 1).toString();
		var DD = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
		var date = YY + '-' + MM + '-' + DD;
		return date;
 	},
 	dateSplit : function (num) {
 		var dateStr = num.toString();
			return dateStr.substr(0, 4) + '-' + dateStr.substr(4, 2) +
			'-' + dateStr.substr(6, 2);
 	},
 	extractArr : function (arr, str) {
 		var self = this;
		var arrayObj = [];
		if (str == 'time') {
			$.each(arr, function(i, n) {
				arrayObj.push(self.timeStamp(n[str] * 1000));
			});
		} else {
			$.each(arr, function(i, n) {
				arrayObj.push(n[str]);
			});
		}
		return arrayObj;
 	},
 	judgeIntime : async function (arr) {
 		var timeStamp = await this.thsQuote.getServerTime();
		var d = new Date(timeStamp * 1000);
		var current = d.getHours() * 60 + d.getMinutes();
		var arrBegin = arr[0].split(':');
		var arrEnd = arr[1].split(':');
		var b = parseFloat(arrBegin[0], 10) * 60 + parseFloat(arrBegin[1], 10);
		var e = parseFloat(arrEnd[0], 10) * 60 + parseFloat(arrEnd[1], 10);
		if (current >= b && current <= e) {
			return true;
		} else {
			return false;
		}
 	},
 	preMonthDate : async function () {
 		var timeStamp = await this.thsQuote.getServerTime();
 		var time = new Date(timeStamp * 1000 - 30 * 24 * 3600 * 1000);
 		var date = this.timeStamp(time);
 		return date;
 	},
 	getTradingDay : async function () {
 		var today = await this.serverTime();
 		var tradingDay = await this.thsQuote.getSHTradeDate(today);
 		return tradingDay;
 	},
 	arrayIntersection : function(arr1, arr2) {
		var ai = 0,
			bi = 0;
		var result = [];
		while (ai < arr1.length && bi <arr2.length) {
			if (arr1[ai] <arr2[bi]) {
				ai++;
			} else if (arr1[ai] > arr2[bi]) {
				bi++;
			} else {
				result.push(arr1[ai]);
				ai++;
				bi++;
			}
		}
		return result;
	}

 };